<template>
	<view>
		<skeletons :loading="loading" :rowsHeight="['95vh']">
			<view class="map-box" v-if="mapKey">
				<template v-if="isShowMap">
					<vue3Map @commitCheck="commitCheck" :mapKey='mapKey' :Radius='Radius'
						:showResetting='showResetting' :listIco='listIco' :orientationIco='orientationIco'
						:resettingIco='resettingIco' :configData='configData'></vue3Map>
				</template>
			</view>
		</skeletons>
	</view>

</template>

<script>
	import api from '@/api'
	import { accredit } from '@/hooks/useAppPermission/index';
	import vue3Map from '@/pages/map/uni_components/vue3-map/components/vue3-map/vue3-map.vue'
	export default {
		data() {
			return {
				mapKey: '',
				address: '',
				latitude: '',
				longitude: '',
				listIco: 'https://xjs-oss-prod.oss-cn-shenzhen.aliyuncs.com/xjs-static/map-item-inx.png',
				orientationIco: 'https://xjs-oss-prod.oss-cn-shenzhen.aliyuncs.com/xjs-static/map-map-inx.png',
				resettingIco: "https://xjs-oss-prod.oss-cn-shenzhen.aliyuncs.com/xjs-static/map-position.png",
				showResetting: true,
				Radius: '',
				// 微信公众号jsSdk配置
				configData: {
					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: '', // 必填，公众号的唯一标识
					timestamp: '', // 必填，生成签名的时间戳
					nonceStr: '', // 必填，生成签名的随机串
					signature: '', // 必填，签名

				},
				isShowMap: true,
				loading: true,
				mapKeyArr: []
			};
		},
		async onLoad() {
			// #ifdef APP
			const status = await accredit('ACCESS_FINE_LOCATION')
			if (status != 1) return
			// #endif
			this.loading = true
			await this.getkey()
			uni.$on('checkMaplimit', (e) => {
				//e为true表示成功 - 10044表示次数用完则重新随机key
				if (e.errCode == "10044") {
					this.isShowMap = false
					let randomNum = Math.floor(Math.random() * this.mapKeyArr.length)
					this.mapKey = this.mapKeyArr[randomNum]
					setTimeout(() => {
						this.isShowMap = true
					}, 1000)
				}
			})
		},
		components:{vue3Map},
		methods: {
			commitCheck(e) {
				console.log(e);
				uni.$emit('commitCheck', e);
				uni.navigateBack({
					delta: 1
				});
			},
			async getkey() {
				const res = await api({
					method: 'get',
					prefix: 'acc',
					url: `/content/backend-configs/getGaoDeMapKey`
				})
				this.mapKeyArr = JSON.parse(res.data.value)
				let randomNum = Math.floor(Math.random() * this.mapKeyArr.length)
				this.mapKey = this.mapKeyArr[randomNum]
				this.loading = false
			},
		}
	};
</script>

<style lang="scss">
	.map-box {
		height: 100vh;
		width: 100vw;
	}
</style>